﻿using Nop.Core.Domain.Logistics;
using System.Data.Entity.ModelConfiguration;

namespace Nop.Data.Mapping.Logistics
{
    public class ZoneGroupMap : EntityTypeConfiguration<ZoneGroup>
    {
        public ZoneGroupMap()
        {
            this.ToTable("LogisticsZoneGroup");
            this.HasKey(zg => zg.Id);

            this.Property(zg => zg.Name)
                .IsRequired()
                .HasMaxLength(1000);

            this.HasOptional(zg => zg.District)
                .WithMany()
                .HasForeignKey(zg => zg.DistrictId);
            
            this.HasOptional(zg => zg.Courier)
                .WithMany()
                .HasForeignKey(z => z.DistrictId);

            this.HasMany(zg => zg.Zones)
                .WithOptional(z => z.ZoneGroup)
                .HasForeignKey(z => z.ZoneGroupId);
        }
    }
}
